
// 公共方法
(()=>{
    class Scroll {
		/**
		 *
		 * @param dom 父容器(ul)的id
		 * @param _h 子元素li的高度
		 * @param interval 3000  滚动间隔时间
		 */
        constructor(dom: string, _h: string, interval: number) {
            var NodeList: any = document.getElementById(dom);
            var timer = setTimeout(()=> {
                var _field = NodeList.firstElementChild;
                _field.style.marginTop = _h;
                clearTimeout(timer);
            }, 1000);
            setInterval(()=> {
                var _field = NodeList.firstElementChild;
                _field.style.marginTop = '0px';
                NodeList.appendChild(_field);
                var _field = NodeList.firstElementChild;
                _field.style.marginTop = _h;
            }, interval);
        }
    }


    //正规网站公用函数
    class publicJavaScriptfunction {


        





        
    }

    function ScRoll (id:string,distance:string,time:number):any{

        let Roll=null;

        return Roll || (Roll = new Scroll(id,distance,time));
    }  
    let wd:any = window;
    wd['Scroll'] = ScRoll;

})();


(()=>{

    // 移动PC 通用模板
    class General{


        /**
		 *底部新闻 右边 描述 左新闻 可向上循环移动
		 * @param lettitle string length in min 3
		 * @param newLst Array object {src:'',txt}
         * @param time 间隔时间 默认为3000
		 */
        newspapers(lettitle: string, newLst: Array<object>,time = 3000): string{
            this.isArray(newLst);
           
            this.delayed(`Scroll('scroll', '-4rem', ${time})`,200);

            // 只能传入 数组对象
            let tp = '';
            if (newLst instanceof Array) {
                [...newLst].forEach((element: any) => {
                    tp += `<li><a href="${element.src}" style='margin-left: 2rem;color: white;'> <strong>${element.txt}</strong></a></li>`;
                });
            }

            return `<div class="publictemplatestyle MonotonicShut-off overleaf">
			<div class="description">
				<strong>${lettitle.length >= 3 ? lettitle.substring(0, 3) : lettitle}</strong>
			</div>
			<div>
				 <ul style="width:80%;height:4rem;overflow:hidden;line-height:4rem;" id="scroll"> 
                        ${tp}
				</ul> 
			</div>
			<div>
                ${this.templateMobile('shut_off')}
			</div>
			 ${this.templateMobile('signboard')}
		</div>`;

        }

    }

    function GeneralPublick(e:any,...data:any){

        let single=null;

        return single || (single = new General()[e](data) )
    }
})();


// 移动模板
(()=>{
    const Frames = `*{padding:0;margin:0}html body{width:100%;height:100%}a{text-decoration:none}a:link{color:blue;text-decoration:none}a:hover{color:red;text-decoration:underline}a:active:{color:red}a:visited{color:black;text-decoration:none}.publictemplatestyle{width:98%;height:6.4rem;margin:0.6rem;margin:1%;background-color:rgba(0,0,0,0.2)}h1 h2 h3 h4 h5 h6{margin-left:10px;line-height:0px}img{animation:fade-in;animation-duration:1s;-webkit-animation:fade-in 1.5s}strong{color:white}div>strong{color:white}.overleaf{position:fixed;bottom:5rem;z-index:2147483647!important}.publictemplatestyle>table{width:100%;height:auto;background:rgba(0,0,0,0.5);color:white}.publictemplatestyle>table>tbody>tr{text-align:center;line-height:3rem}.publictemplatestyle>table>tbody>tr:nth-last-child(){}.publictemplatestyle>table>tbody>td{text-align:center}.publictemplatestyle>table>tbody>td:nth-last-child(){}.zuoyoutuwen{background:rgba(0,0,0,0.18);display:flex;display:-webkit-flex;display:inline-flex}.zuoyoutuwen>.let{width:50%;height:100%;display:flex-direction}.zuoyoutuwen>.let>img{width:100%;height:100%}.shoumeges{display:flex;display:-webkit-flex;height:100%}.imgAdvertisementForm>.shoumeges>div{text-align:center;flex-grow:3;height:100%}.shoumeges>div>img{width:100%;height:100%;height:auto;max-width:100%;max-height:100%;animation:animated-border 1s infinite;font-family:Arial;font-size:18px;line-height:30rpx;font-weight:bold;color:#8f8f94;border-radius:10px;animation:fade-in;animation-duration:2s;-webkit-animation:fade-in 1.5s}.titleImges>img{width:100%;height:100%}.MonotonicShut-off{display:flex;display:-webkit-flex;background:rgba(0,0,0,0.18);height:4rem;overflow:hidden}.MonotonicShut-off>div{flex-grow:3;justify-content:space-around}.MonotonicShut-off>div:nth-child(2){width:70%}.MonotonicShut-off>div:nth-child(2)>a>strong{line-height:4rem}.MonotonicShut-off>div:nth-child(3){width:5%}.MonotonicShut-off>div:nth-child(3)>p{line-height:4rem;text-align:center}.description{width:3rem;height:100px;background-color:#aa0000;position:relative}.description:after,.description:before{border:solid transparent;content:" ";height:0;left:100%;position:absolute;width:0}.description:after{border-left-color:#aa0000;top:-2.5rem}.description:before{border-width:2rem;border-left-color:#aa0000}.description>strong{line-height:4rem;margin-left:1rem;color:white}#close{display:inline-block;width:1.2rem;height:4px;background:#333;transform:rotate(45deg)}#close::after{content:"";display:block;width:1.2rem;height:4px;background:#333;transform:rotate(-90deg)}@keyframes fade-in{0%{opacity:0}40%{opacity:0}100%{opacity:1}}@-webkit-keyframes fade-in{0%{opacity:0}40%{opacity:0}100%{opacity:1}}@keyframes animated-border{0%{box-shadow:0 0 0 0 rgba(255,255,255,0.4)}90%{box-shadow:0 0 0 10px rgba(255,255,255,0)}}.slide{margin:auto;width:600px;height:200px;text-align:center;font-family:Arial;color:#fff;overflow:hidden}.slide ul{margin:10px 0;padding:0;width:9999px;transition:all 0.5s}.slide.slide-auto{animation:marginLeft 10.5s infinite}.slide li{float:left;width:600px;height:200px;list-style:none;line-height:200px;font-size:36px}.slide li:nth-child(1){background:#9fa8ef}.slide li:nth-child(2){background:#ef9fb1}.slide li:nth-child(3){background:#9fefc3}@keyframes marginLeft{0%{margin-left:0}28.5%{margin-left:0}33.3%{margin-left:-600px}62%{margin-left:-600px}66.7%{margin-left:-1200px}95.2%{margin-left:-1200px}100%{margin-left:0}}.banner{width:100%;height:9.4rem;overflow:hidden;margin:0 auto}.inner{width:9999px;position:relative;animation:aaa 16s infinite 2s running}@keyframes aaa{0%{transform:translateX(0px)}5%{transform:translateX(-640px)}25%{transform:translateX(-640px)}30%{transform:translateX(-1280px)}50%{transform:translateX(-1280px)}55%{transform:translateX(-1920px)}75%{transform:translateX(-1920px)}80%{transform:translateX(-2560px)}100%{transform:translateX(-2560px)}}.inner:hover{animation-play-state:paused;cursor:pointer}.innerwrapper{float:left;width:640px}.banner img{width:100%;height:300px}.AdvertisingLogo{position:absolute;right:0px;background:#000000;color:white;bottom:0px}#father{position:fixed;top:0;z-index:2147483647!important;width:100%;height:100%;background-color:rgba(0,0,0,0.7);display:flex;justify-content:center;align-items:center}#son{width:50%;height:50%;background-color:green;border-radius:1rem}#son>div{background-size:cover;background-attachment:fixed;background-repeat:no-repeat}.alertbox{width:80%;height:20%;background:rgba(255,255,255,0.95);border-radius:1rem;box-shadow:3px 1px 72px#888888;border:1px solid#007aff}.toptext{width:100%;height:70%;border-bottom:1px solid#007aff;display:flex;justify-content:center;align-items:center}.buottnbt{width:100%;height:30%;border-radius:2rem}.toptext h3{text-align:center}.let{width:49.5%;height:100%;float:left;border-radius:1rem;text-align:center;font-weight:600;display:flex;justify-content:center;align-items:center;color:#007aff}.let:active{background:#4a9bfa;background-color:rgba(0,0,0,0.2)}.rets{border-left:1px solid;border-top-left-radius:0em;border-top-right-radius:0em;border-bottom-right-radius:1em;border-bottom-left-radius:0em}#father{position:fixed;top:0;width:100%;height:100%;background-color:rgba(0,0,0,0.7);display:flex;justify-content:center;align-items:center;z-index:2147483647!important}#son{width:80%;height:90%;background-color:green;border-radius:1rem}#son>div{background-size:cover;background-attachment:fixed;background-repeat:no-repeat}.Mixlocs{position:absolute;right:2.5rem;background-color:rgba(0,0,0,0.2);line-break:normal;top:2rem;letter-spacing:0.5rem;color:#ffffff;padding:0.5rem;border-radius:1rem}.box{position:fixed;top:0;width:100%;height:100vh;margin:0 auto;background-repeat:no-repeat;background-size:cover;overflow:auto;z-index:2147483647!important}._container{overflow:hidden;text-align:center}._container li{width:100%;font-size:18px}._container li:first-child{margin-top:0;transition:margin-top 2s}.bouttBox{width:100%;background-color:#007AFF;height:10rem}.bouttBox ul{width:100%;height:100%}.bouttBox ul>li{width:100%;height:100%}.bouttBox ul>li img{width:100%height:100%}.contter{width:100%;height:100%;display:-webkit-flex;overflow:hidden}.contter>a{width:100%;height:100%}.contter>a>img{width:100%;height:85%;height:auto;max-width:100%;max-height:85%;animation:animated-border 1s infinite;font-family:Arial;font-weight:bold;color:#8f8f94;animation:fade-in;animation-duration:2s;-webkit-animation:fade-in 1.5s}`;
    const style = document.createElement('style');
    style.type = 'text/css';
    style.id = 'setstyle';
    style.innerHTML = Frames;
    document.querySelectorAll('head')[0].appendChild(style);

    interface confirmCentre {
        title: string | undefined;
        confirm: string | '确定';
        cance: string | '取消';
        src: string | 'https:www.baidu.com';
    }

    class CommercialTemplate {
        constructor(sw = false) {
            setTimeout(() => {
                this.publicJavaScript(sw);
            }, 500);
        }

        publicJavaScript(autoclos: boolean) {
            let num: number = 5,
                getDom: any | null,
                Mixlocs: any | undefined;

            // num = 5; // 默认为5秒跳出广告
            Mixlocs = document.getElementsByClassName('Mixlocs')[0];
            if (!Mixlocs) return false;
            getDom = Mixlocs.children[0];
            getDom.innerText = num;
            const interval = setInterval(function () {
                num--;
                getDom.innerText = num;
                if (num == 0) {
                    var tg = getDom.parentNode;

                    tg && (tg.innerHTML = '跳过');
                    if (autoclos) {
                        if (Mixlocs.parentNode.id === 'father') {
                            Mixlocs.parentNode.remove();
                            return false;
                        }
                        Mixlocs.parentNode.parentNode.remove();
                    }
                    if (tg.innerHTML === '跳过') {
                        tg.onclick = function () {
                            this.parentNode.remove();
                            return false;
                        };
                    }
                    clearInterval(interval);
                }
            }, 1000);
        }

        /**
         * 判断当前的是否是数组，否是就停止后面程序
         * @param ArrAy 数组
         */
        isArray(arratobj:Array<any>){

            if(!Array.isArray(arratobj)){
                return false;
            }
        }


        /**
         * 延时执行函数
         * @param fun 需要延时的函数 string
         * @param time 需要延时的时间 number
         */
        delayed(fun:any,time:number){  
            
            setTimeout(()=>{eval(fun);},time);

        }

		/**
		 * 公共样式
		 * @param e 样式key值
		 * @param img 所需要的图片
		 */
        common(e: any, img?: string | undefined): string {
            const communalFacilities: any = {
                w_h100: `width: 100%;height: 100%;`,
                backgImage: `background-image:url(${img}`,
                color: `color: #007aff`
            };

            return communalFacilities[e];
        }

		/**
		 *
		 * @param e 公共html模板key值
		 */
        templateMobile(e: string): string {
            const template: any = {
                signboard: `<div class="AdvertisingLogo" style='z-index: 2147483647!important;' >广告</div>`,
                wait: ` <div class="Mixlocs">广告<span>3</span></div>`,
                shut_off: `	<p><span id="close"></span></p>`
            };
            return template[e];
        }
		/**
		 *
		 * @param src 全屏广告
		 */
        fullScreen(img: string, src: string): string {
            return `<a href="${src}"><div class="box" style="${this.common('backgImage', img)});">
        ${this.templateMobile('wait')}
        ${this.templateMobile('signboard')}
        </div></a>`;
        }

		/**
		 *
		 * @param src 全屏中间位置位置
		 */
        middlePosition(img: string, src: string): string {
            return `<a href="${src}">	<div id="father">
            ${this.templateMobile('wait')}
            <div id="son">
                <div style="${this.common('w_h100')}${this.common('backgImage', img)});border-radius: 1rem;"></div>
                ${this.templateMobile('signboard')}
            </div>
        </div></a>`;
        }

		/**
		 * 弹出框
		 * @param obj object
		 *
		 * title 显示的广告标题
		 * confirm 确定按钮
		 * cance 取消按钮
		 * src 广告路径
		 */

        confirmCentre(title: any, src: string, confirm: string, cance: string, yes: any, Noclos: any): string {
            setTimeout(() => {
                var mm: any = document.getElementsByClassName('buottnbt')[0].children;
                mm[0].onclick = function () {
                    if (yes) {
                        eval(`(${yes})()`);
                    } else {
                        window.location.href = src;
                    }

                    console.log('确定');
                    // window.location.href = src;
                };
                mm[1].onclick = function () {
                    console.log();
                    if (Noclos) {
                        eval(`(${Noclos})()`);
                    }
                    document.getElementById('father') && document.getElementById('father').remove();
                };
            }, 500);

            const hh3 = `<h3>${title}</h3>`;
            const img = `<img src="${title}" style='border-radius: 1rem 1rem 0 0;${this.common('w_h100')}'>`;
            return `<div id="father">
           ${this.templateMobile('wait')}
            <div class="alertbox">
                <div class="toptext">
                <a href="${src}" style='${this.common('w_h100')}'>
                ${title.startsWith('https://') ? img : title.startsWith('http://') ? img : hh3}</a>
                </div>
                <div class="buottnbt">
                    <div class="let">
                        <strong style='${this.common('color')}'>${!confirm ? '确定' : confirm}</strong>
                    </div>
                    <div class="rets let">
                        <strong style='${this.common('color')}'>${!cance ? '取消' : cance}</strong>
                    </div>
                </div>
            </div>
            ${this.templateMobile('signboard')}
        </div>`;
        }

		/**
		 * 底部多张图片
		 * @param img 广告图片
		 * @param src Array 广告路径
		 */
        downtitleImges(title: string, src: string, arrimg: any) {
            let tp = '';
            const ImgtPath: Array<string> = arrimg.split(',');

            if (ImgtPath.length == 1) {
                tp = `<div>
                <img alt="穿职业装扮的尤里酱，让人眼前一亮，更有女人味了" class="lazy" data-original="http://upcdn.sdkv.top/250x250/aHR0cHM6Ly95LnZpcDk5Lnh5ei93cC1jb250ZW50L3VwbG9hZHMvc2hpcGluLzAwMDBfMDBfMDAvMWhzZzRoYXNyZHkubXA0LjBfMC5wMC5qcGc="
                 src="${arrimg}"
                 style="display: inline;">
            </div>`;
            } else if (ImgtPath.length > 1) {
                ImgtPath.forEach(item => {
                    console.log(item);
                    tp += `<div>
                    <img alt="穿职业装扮的尤里酱，让人眼前一亮，更有女人味了" class="lazy" data-original="http://upcdn.sdkv.top/250x250/aHR0cHM6Ly95LnZpcDk5Lnh5ei93cC1jb250ZW50L3VwbG9hZHMvc2hpcGluLzAwMDBfMDBfMDAvMWhzZzRoYXNyZHkubXA0LjBfMC5wMC5qcGc="
                     src="${item}"
                     style="display: inline;">
                </div>`;
                });
            }
            return `<div class="imgAdvertisementForm publictemplatestyle overleaf">
            <a href='${src}'><strong>${title}</strong></a>
            <div class="shoumeges ">
               ${tp}
            </div>
            ${this.templateMobile('signboard')}
        </div>`;
        }

		/**
		 * 左边图片右边文字
		 * @param img 广告图片
		 * @param src 广告路径
		 * @param title 广告标题
		 */

        downmaster(img: string, src: string, title: string): string {
            return `<div class="zuoyoutuwen publictemplatestyle overleaf">
            <div class="let">
                <img src="${img}">
            </div>
            <div class="relt let">
                <strong><a href="${src}">${title}</a></strong>
            </div>
            ${this.templateMobile('signboard')}
        </div>`;
        }

		/**
		 *底部新闻 右边 描述 左新闻 可向上循环移动
		 * @param lettitle string length in min 3
		 * @param newLst Array object {src:'',txt}
         * @param time 间隔时间 默认为3000
		 */
        dowjournalism(lettitle: string, newLst: Array<object>,time = 3000): string {

            this.isArray(newLst);
           
            this.delayed(`Scroll('scroll', '-4rem', ${time})`,200);

            // 只能传入 数组对象
            let tp = '';
            if (newLst instanceof Array) {
                [...newLst].forEach((element: any) => {
                    tp += `<li><a href="${element.src}" style='margin-left: 2rem;color: white;'> <strong>${element.txt}</strong></a></li>`;
                });
            }

            return `<div class="publictemplatestyle MonotonicShut-off overleaf">
			<div class="description">
				<strong>${lettitle.length >= 3 ? lettitle.substring(0, 3) : lettitle}</strong>
			</div>
			<div>
				 <ul style="width:80%;height:4rem;overflow:hidden;line-height:4rem;" id="scroll"> 
                        ${tp}
				</ul> 
			</div>
			<div>
                ${this.templateMobile('shut_off')}
			</div>
			 ${this.templateMobile('signboard')}
		</div>`;
        }

        /**
         * 图片文字描述向上滚动
         * @param obj  ArrAy object {src：‘点击后的链接’，txt：‘显示的文字’,img:'显示的图片'}
         */

        shufflingthe(obj: Array<object>,time:number): string {
            this.isArray(obj);
            this.delayed(`Scroll('Imgse_Fuck', '-10rem', ${time})`,200);

            let tp='';
            [...obj].forEach((e:any)=>{
                tp+=` <li>
                <div class="contter">
                    <a href="${e.src}">
                        <strong>${e.txt}</strong>
                        <img src="${e.img}" alt="">

                    </a>
                </div>
            </li>`;
            })


            return `
        <div class="bouttBox">
            <ul class="_container" id="Imgse_Fuck">
            ${tp}
        </ul>
		</div>
        
        `
        }
    }



    function FormalTemplate(of: boolean = false, type: string, ...prpy: any): any {
        let exist = null;

        return exist || (exist = new CommercialTemplate(of)[type](...prpy));
    }
    let wd: any = window;

    wd['FormalTemplate'] = FormalTemplate;



})();



// PC模板
(()=>{













})()